<?php
class ujn_controller {

	function getHttpReferer() {
		return tls_func::get_http_referer();
	}

	function redirect($url, $type = 'html') {
		tls_func::redirect($url, $type);
	}


	var $show_action_error = true;
	var $auto_render = true;
	function _before() { }
	function _after() { }

	protected $vars = array();
	public function assign($name, $var=null) {
		if(is_string($name) && !is_null($var)) {
			$name = array($name => $var);
		}
		if(!is_array($name)) $name = array($name);
		$this->vars = array_merge_recursive($this->vars, $name);
		return $this;
	}

	protected $_viewpath = '';
	public function getViewPath($action_name) {
		$templates_path = ujn::getCFG('templates_path');
		if('' != $this->_viewpath) {
			$view_path = $templates_path . $this->_viewpath;
		} else {
			$class_name = get_class($this);
			$view_path = $templates_path . ( $class_name == 'ujn_controller' ? '' : get_class($this) . '/' ) . "$action_name.php";
		}

		return $view_path;
	}
	public function isViewPathExists($path) {
		return is_file(ujn::getCFG('templates_path') . $path);
	}
	public function setViewPath($path) {
		$this->_viewpath = $path;
	}
	public function getViewVars() {
		return $this->vars;
	}
}